import { game } from "../../../../script/game/control/game";
import { eduType, schoolType } from "../../../../script/game/gameType";
import { ListViewAdapter } from "../../../../script/util/ListView/ListViewAdapter";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {
    @property(ListViewAdapter)
    list: ListViewAdapter = null;
    
    @property(cc.Node)
    tips: cc.Node = null;

    type: string = null;
    
    start () {
        ccs.gf.extendNodeName(this.nodes, this.node.parent);
        this.updateItems();
        this.registerEvent("updateSchool", () => {
            this.updateItems();
        });
    }
    updateItems() {
        let age = game.playerMgr.heroInfo.age;
        if(game.playerMgr.getSchool()) {
            age -= game.playerMgr.heroInfo.school.year - game.playerMgr.heroInfo.school.leftYear;
        }
        let edu = ccs.dataMgr.getEduByAge(age);
        let myEdu = game.playerMgr.heroInfo.edu;
        if(game.playerMgr.heroInfo.school && game.playerMgr.heroInfo.school.year > 0 && game.playerMgr.heroInfo.school.state == 1) {
            this.nodes.inSchool.active = true;
            this.nodes.right.active = false;
            this.tips.active = false;
            this.setEduInfo(game.playerMgr.heroInfo.school);
            return ;
        } else {
            this.nodes.inSchool.active = false;
            this.nodes.right.active = true;
        }
        if(edu.id != "wu") {
            //查看当前的学历状态
            if(myEdu.type == edu.need || edu.need == "wu") {
                let items = ccs.dataMgr.getSchoolByEdu(edu.type);
                this.list.updateItems(items);
                this.nodes.right.active = true;
                this.tips.active = false;
            }
        } else {
            this.nodes.right.active = false;
            this.tips.active = true;
        }
    }
    setEduInfo(edu: schoolType) {
        this.nodes.name.getComponent(cc.Label).string = edu.name.toString();
        this.nodes.pro.getComponent(cc.Label).string = `专业：${edu.work == 0? "无": ccs.dataMgr.getAttributeNameById(edu.work).name}`;
        this.nodes.age.getComponent(cc.Label).string = `学年：${edu.leftYear}`;
        this.nodes.power.getComponent(cc.Label).string = `精力：${edu.power}`;
        this.nodes.money.getComponent(cc.Label).string = `学费：${edu.price}`;
    }
}
